package com.ats.impl.tws

import org.slf4j.{Logger, LoggerFactory}
import com.ib.client.Contract

import com.hazelcast.core.MultiMap;
import com.hazelcast.core.Hazelcast
import com.ats.common.Constants

import java.util.List
import com.ats.api.model.{TickData, HistoricalTickData, Trade}

;

/*
 Messages received from TWS

*/
class EWrapperAdapter {
  private final val logger = LoggerFactory.getLogger(getClass());


  def updatePortifolio(contract: Contract, position: Int, marketPrice: Double, marketValue: Double, avgCost: Double, unrealizedPNL: Double, realizedPNL: Double, accountName: String) {
    var tradeList: List[Trade] = Hazelcast.getList(Constants.TRADES_LIST);
    var trade = new Trade();
    trade.contract = contract;
    trade.price = avgCost;
    tradeList.add(trade);
  }

  def updateAccountValue(s: String, s1: String, s2: String, s3: String) {

  }

  def updateAccountTime(time: String) {
    logger.debug("updateAccountTime" + time);
  }

  def tickPrice(tickerId: Int, field: Int, price: Double, canAutoExecute: Int) {
    // val tickData = new TickData();

    //logger.debug();
  }

  def tickString(i: Int, i1: Int, s: String) {

  }

  def orderStatus(i: Int, s: String, i1: Int, i2: Int, d: Double, i3: Int, i4: Int, d1: Double, i5: Int, s1: String) {

  }


  def sendHistoricalData(tickData: HistoricalTickData) {
    System.out.println("");
  }

  def connectionClosed() {
    System.out.println("Connection closed Mesg received");
  }

  def error(errorMsg: String) {
    System.out.println("Error" + errorMsg);

  }

  def error(tickerIdOrOrderId: Int, errorCode: Int, errorMsg: String) {
    System.out.println("" + tickerIdOrOrderId + errorCode + errorMsg);
  }

}